package com.ruoyi.amuse.comments.controller;


import com.ruoyi.amuse.comments.domain.PostComments;
import com.ruoyi.amuse.comments.service.IPostCommentsService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 评论管理Controller
 * 
 * @author juwujie
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/comments/comments")
public class PostCommentsController extends BaseController
{
    @Autowired
    private IPostCommentsService postCommentsService;

    /**
     * 查询评论管理列表
     */
    @RequiresPermissions("comments:comments:list")
    @GetMapping("/list")
    public TableDataInfo list(PostComments postComments)
    {
        startPage();
        List<PostComments> list = postCommentsService.selectPostCommentsList(postComments);
        return getDataTable(list);
    }

    /**
     * 导出评论管理列表
     */
    @RequiresPermissions("comments:comments:export")
    @Log(title = "评论管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PostComments postComments)
    {
        List<PostComments> list = postCommentsService.selectPostCommentsList(postComments);
        ExcelUtil<PostComments> util = new ExcelUtil<PostComments>(PostComments.class);
        util.exportExcel(response, list, "评论管理数据");
    }

    /**
     * 获取评论管理详细信息
     */
    @RequiresPermissions("comments:comments:query")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(postCommentsService.selectPostCommentsByCommentId(commentId));
    }

    /**
     * 新增评论管理
     */
    @RequiresPermissions("comments:comments:add")
    @Log(title = "评论管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PostComments postComments)
    {
        return toAjax(postCommentsService.insertPostComments(postComments));
    }

    /**
     * 修改评论管理
     */
    @RequiresPermissions("comments:comments:edit")
    @Log(title = "评论管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PostComments postComments)
    {
        return toAjax(postCommentsService.updatePostComments(postComments));
    }

    /**
     * 删除评论管理
     */
    @RequiresPermissions("comments:comments:remove")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(postCommentsService.deletePostCommentsByCommentIds(commentIds));
    }
}
